<template>
  <div class="profile">
    <header @click="goLogin()">
      <h3>
        <img v-if="loginStatus" :src=" userInfo.imgUrl ">
        <img v-else src="@/assets/images/icons/my.png">
      </h3>
      <h3>{{ loginStatus ? userInfo.nickname : '登录/注册' }}</h3>
    </header>
    <section>
      <div v-if="loginStatus" @click="goPath()">地址管理</div>
      <div v-if="loginStatus" @click="out()">退出登录</div>
    </section>
  </div>
</template>

<script>
import {mapState,mapMutations} from 'vuex'
export default {
  name: "profile",
  components: {

  },
  computed:{
    ...mapState({
      userInfo: state => state.user.userInfo,
      loginStatus: state => state.user.loginStatus
    })
  },
  methods:{
    ...mapMutations(['loginOut']),
    goLogin(){
      this.$router.push({
        path:'/Login'
      })
    },
    out(){
      this.loginOut()
    },
    //跳转到地址管理
    goPath(){
      this.$router.push('/address')
    }
  }
}
</script>

<style scoped lang="scss">
header{
  display: flex;
  align-items: center;
  width: 100%;
  height: 100px;
  background-color: #F4F4F4;
  div,h3{
    padding-left: 20px;
  }
  img{
    width: 64px;
    height: 64px;
    border-radius: 100%;
  }
}
section{
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  div{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 32px;
    margin: 10px 0px;
    text-align: center;
    color: #F4F4F4;
    background-color: orange;
  }
}
</style>